package com.service.bean.device;

import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.service.bean.alarm.AlarmRule;
import com.service.bean.area.Area;
import com.service.bean.company.Company;
import com.service.bean.duty.VehicleDuty;
import com.service.bean.oil.OilBean;
import com.service.bean.oil.OilBox;
import com.service.bean.oil.OilCard;
import com.service.bean.point.GarbageCollectionPoint;
import com.service.bean.point.LabelPoint;
import com.service.bean.signal.GpsSignal;

public class Vehicle {
	/**
	 * 车辆Id
	 */
	public String equipmentId;
	/**
	 * 车牌号
	 */
	public String plateNO;
	/**
	 * Gps总里程
	 */
	public double totalMile;
	/**
	 * 车辆里程表总里程
	 */
	public double totalMile2;
	/**
	 * 记录本次总里程的时间(Gps)
	 */
	public Date totalMileTime;
	/**
	 * 记录本次总里程的时间(车辆里程表)
	 */
	public Date totalMileTime2;
	
	public int whetherStrength;//工作状态判断条件
	/**
	 * 邮箱
	 */
	public OilBox oilBox;
	/**
	 * Gps终端
	 */
	public Device device;
	/**
	 * 车辆所属公司
	 */
	public Company company;
	/**
	 * 车辆传感器集合
	 */
	public Map<String,Sensor> sensorMap = new HashMap<String,Sensor>();
	/**
	 * 车辆绑定报警集合
	 */
	public Map<String,AlarmRule> alarmRuleMap = new HashMap<String,AlarmRule>();
	/**
	 * 车辆规划区域集合
	 */
	public Map<String,Area> areaMap = new LinkedHashMap<String,Area>();

	/**
	 * 计算完油量、里程等变化量后的上一条数据
	 */
	public GpsSignal lastGps;
	/**
	 * 上一条终端发送过来，经过初步解析后的数据(乱序，不按时间排序)
	 */
	public GpsSignal lastGps_Received;
	/**
	 * 按时间排序后最新一条Gps信号
	 */
	public GpsSignal lastGps_lastest;
	/**
	 * 油量计算相关
	 */
	public LinkedList<Double> lastList;
	/**
	 * 油量对象
	 */
	public OilBean oilBean;
	/**
	 * 油卡
	 */
	public OilCard oilCard;
	/**
	 * 油价
	 */
	public double fuelPrice;
	/**
	 * 车辆排班
	 */
	public VehicleDuty duty;
	/**
	 * 车辆类型
	 */
	public String kindCode;
	/**
	 * 该车辆设定的正常油耗值
	 */
	public double normalOilValue;
	/***
	 * 车辆类型编号
	 */
	public String equipmentCategoryCode;

	/**
	 * 车辆标注点--加水点(H)
	 */
	public Map<String, List<LabelPoint>> wateringAddPoints = new HashMap<String, List<LabelPoint>>();
	/**
	 * 车辆标注点--垃圾倾倒点(I)
	 */
	public Map<String, List<LabelPoint>> dumpPoints = new HashMap<String, List<LabelPoint>>();
	/**
	 * 车辆标注点--污水排放点(J)
	 */
	public Map<String, List<LabelPoint>> dischargePoints = new HashMap<String, List<LabelPoint>>();
	/**
	 * 车辆标注点--收集点(K)
	 */
	public Map<String, List<LabelPoint>> collectionPoints = new HashMap<String, List<LabelPoint>>();
	/**
	 * 转速比
	 */
	public double pumpRated;
	/**
	 * 泵额定转速
	 */
	public double rotationalSpeed;
	/**
	 * 泵排量 
	 */
	public double pumpDelivery;	
		/**
	 * 垃圾称重收集点
	 */
	public Map<String, List<GarbageCollectionPoint>> garbagePoints = 
			new LinkedHashMap<String, List<GarbageCollectionPoint>>();
	
	/**
	 * 当车辆没有排班时,返回车辆的规划区域;否则返回车辆排班区域
	 * @return
	 */
	public Map<String, Area> getAreas() {
		if (null == duty || null == duty.areas || 0 == duty.areas.size())
			return areaMap;
		return duty.areas;
	}
	
	/**
	 * 更新最新时间的signal信号数据
	 */
	public void setLastGps_lastest(GpsSignal signal){
		if (null == lastGps_lastest 
			|| lastGps_lastest.gpsTime.before(signal.gpsTime))
			lastGps_lastest = signal;
	}
	
	/**
	 * 前端E0命令获取最新时间的signal信号数据
	 */
	public GpsSignal getLastGps_Received() {
		
		if(lastGps_lastest == null){
			return lastGps;
		}
		if(lastGps == null){
			return lastGps_Received;
		}
		
		if (lastGps.gpsTime.before(lastGps_lastest.gpsTime)){
			//历史数据的时间比缓存里的时间新，返回历史数据
			return lastGps_lastest;
		}else{
			return lastGps;
		}		
	}
	
}

